package cn.kgc.shiro;

import cn.hutool.core.util.RandomUtil;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * shiro安全框架的加密操作
 */
public class App {

    public static void main(String[] args) {

        // 明文密码
        String password = "123456";
        // 123456    e10adc3949ba59abbe56e057f20f883e    MD5不可逆
        String hex = new Md5Hash(password).toHex();
        System.out.println("hex = " + hex);

        
        // 明文  + 盐  salt
        // a5ba8e63b71b67942887602f1fd8a238
        String salt = "java2424";

        String hex1 = new Md5Hash(password, salt).toHex();
        System.out.println("hex1 = " + hex1);


        // 明文 + 随机盐   username   password     salt
        //  to1jnmql    27d247eddb660dbf635b25933ada443a
        //  g9txiu1r    aed5c0cb86b58edc6b84457987695e88

        String randomSalt = RandomUtil.randomString(8);
        System.out.println("randomSalt = " + randomSalt);
        // String hex2 = new Md5Hash(password, randomSalt).toHex();
        // System.out.println("hex2 = " + hex2);


        //  增强加密次数    明文 + 随机盐  +  多次散列
        // 9c5896f6f76b0f434d70ec3fa9721db8
        String hex2 = new Md5Hash(password, "java2424", 10).toHex();
        System.out.println("hex2 = " + hex2);


    }
}
